
***************************
// This file contains estimations for Chen and Sullivan 2022 in 
// Journal of Public Administration Research and Theory (JPART), 
// "Should I Stay or Should I Go? Why Participants Leave Collaborative Governance Arrangements"
**************

// First set path

	global path "/Users/andrew/Downloads/xin_jpart/"
	cd $path
	
//
// Collaboration Level Estimations
// Tables 4 and A1
//
	clear all
	
	// Bring in enterprise zone level data
	// Each observation is an enterprise zone
		use $path/ez_level_data.dta
		
	// Set macros for outregs
		local outreg_probit "outreg2 using ezlevel_probit.xls, bdec(3) excel sideway pvalue label"
		local outreg_probit_margin "outreg2 using ezlevel_probit_margin.xls, bdec(3) cttop(Marginal Effect) excel sideway pvalue label"
	
	// Set macros for base model
		local base_model "probit quit z_ez_stable z_num_colla z_imbapower z_income_simi z_race_simi z_muni_share z_home_share z_join_colla_num z_avg_rev z_avg_pop z_avg_income"
		local marg_mac "margins, dydx(*) post"
	
	// Base model
		`base_model' z_jobs_retained z_jobs_created z_umemployment_rate, robust
		// Outreg Table A1, Column 1
			`outreg_probit' replace
		// Take marginal effects
			`marg_mac'
		// Outreg Table 4, Column 1
			`outreg_probit_margin' replace

	// Long term economic variables model
		`base_model' z_retain_long z_jobs_created_long z_unemploy_rate_long, robust
		//Outreg Table A1, Column 2
			`outreg_probit' append
		// Take marginal effects
			`marg_mac'
		// Outreg Table 4, Column 2
			`outreg_probit_margin' append		

	// Non-linear model
		`base_model' z_jobs_retained z_jobs_created z_umemployment_rate z_numb_sqr z_imba_sqr, robust
		// Outreg Table A1, Column 3
			`outreg_probit' append
		// Take marginal effects
			`marg_mac'
		// Outreg Table 4, Column 3
			`outreg_probit_margin' append				

//
// Participant Level Data Cluster at PARTICIPANT Level
// Tables 5 and A2
//
	clear all
	
	//Bring in participant level data
		use $path/part_level_no_dups.dta
		
	// Set macros for outregs
		local outreg_probit "outreg2 using part_probit_cluster.xls, bdec(3) excel sideway pvalue label"
		local outreg_probit_margin "outreg2 using part_probit_margin_cluster.xls, bdec(3) cttop(Marginal Effect) excel sideway pvalue label"
	
	// Set macros for base model
		local base_model "probit quit z_ez_stable z_num_colla z_imbapower z_income_simi z_race_simi z_muni_share z_home_share z_lg_rev z_lg_pop z_lg_income z_HomeRule"
		local base_model_options "==0, vce(cluster ez_id)"
		local pres_econ "z_jobs_retained z_jobs_created z_umemployment_rate"
		local marg_mac "margins, dydx(*) post"
	
	// Base model
		`base_model' `pres_econ' `base_model_options'
		// Outreg Table A2, Column 1
			`outreg_probit' replace
		// Take marginal effects
			`marg_mac'
		// Outreg Table 5, Column 1
			`outreg_probit_margin' replace		

	// Long-term economic variables model
		`base_model' z_retain_long z_jobs_created_long z_unemploy_rate_long `base_model_options'
		// Outreg Table A2, Column 2
			`outreg_probit' append
		// Take marginal effects
			`marg_mac'
		// Outreg Table 5, Column 2
			`outreg_probit_margin' append				
			
	// Non-linear model
		`base_model' `pres_econ' z_numb_sqr z_imba_sqr `base_model_options'
		// Outreg Table A2, Column 3
			`outreg_probit' append
		// Take marginal effects
			`marg_mac'
		// Outreg Table 5, Column 3
			`outreg_probit_margin' append	

	// Non-linear model PLUS participant level variables
		`base_model' `pres_econ' z_numb_sqr z_imba_sqr ///
		z_rev_diff z_rev_diff_imbapower z_late z_pop_diff ///
		z_income_diff z_tyoe_avg z_race_share `base_model_options'
		// Outreg Table A2, Column 4
			`outreg_probit' append
		// Take marginal effects
			`marg_mac'
		// Outreg Table 5, Column 4
			`outreg_probit_margin' append				

	//	
	// Make margins plots
	//
		// Rerun model
			probit quit z_jobs_retained z_jobs_created z_ez_stable ///
			c.z_num_colla##c.z_num_colla c.z_imbapower##c.z_imbapower ///
			z_umemployment_rate z_income_simi z_race_simi z_muni_share ///
			z_home_share z_lg_rev z_lg_pop z_lg_income z_HomeRule z_late ///
			z_pop_diff z_income_diff c.z_imbapower##c.z_rev_diff z_tyoe_avg ///
			z_race_share ==0 , vce(cluster ez_id)
			
		// Figure 1
			margins, at(z_imbapower=(-1.31 (0.1) 2.11))
			
			marginsplot, ciopts(recast(rline) lcolor(gray) lpattern(dash)) ///
			graphregion(fcolor(white)) xtitle("Standardized Resource Imbalance Index") ///
			ytitle("Predicted Likelihood of Participant Dropout") title("") xline(0.59)
			
		// Figure 2
			margins, at(z_num_colla=(-1.406 (0.1) 1.54))
			
			marginsplot, ciopts(recast(rline) lcolor(gray) lpattern(dash)) ///
			graphregion(fcolor(white)) xtitle("Standardized Number of Participants") ///
			ytitle("Predicted Likelihood of Participant Dropout") title("") xline(0.094)

